<div class="portlet">
  <div class="portlet-header">
    <h1><%=t ".title"%></h1>
  </div>
  <div class="portlet-content">

	<% form_for(@contact) do |f| %>
	  <%= f.error_messages %>

          <table>
            <tbody>
              <tr>
                <td>
                  <%= label_tag :first_name, t('activerecord.attributes.contact.first_name') %>
                </td>
                <td>
                  <%= f.text_field :first_name %>
                </td>
              </tr>
              <tr>
                <td>
                  <%= label_tag :last_name, t('activerecord.attributes.contact.last_name') %>
                </td>
                <td>
                  <%= f.text_field :last_name %>
                </td>
              </tr>
              <tr>
                <td>
                  <%= label_tag :sex, t('activerecord.attributes.contact.sex') %><br />
                </td>
                <td>
                  <%= select(:contact, :sex, options_for_select(Contact::SEX.map {|u| [get_sex_label(u),u]}, @contact.sex), :prompt => true) %>
                </td>
              </tr>

              <% if current_user.role?(:role_admin) %>
                <tr>
                  <td>
                    <%= label_tag :email, t('activerecord.attributes.contact.email') %>
                  </td>
                  <td>
                    <%= f.text_field :email %>
                  </td>
                  <% if !@contact.user.nil? %>
                      <td><%=t('lbl_contact_update_user_mail')%></td>
                  <% end %>
                </tr>
              <% end %>
              <tr>
                <td>
                  <%= label_tag :phone, t('activerecord.attributes.contact.phone') %>
                </td>
                <td>
                  <%= f.text_field :phone %>
                </td>
              </tr>
              <tr>
                <td>
                  <%= label_tag :fax, t('activerecord.attributes.contact.fax') %>
                </td>
                <td>
                  <%= f.text_field :fax %>
                </td>
              </tr>
              <tr>
                <td>
                  <%= label_tag :position, t('activerecord.attributes.contact.position') %>
                </td>
                <td>
                  <%= f.text_field :position %>
                </td>
              </tr>
              <% if !@contact.reference.nil? && (@contact.reference_type == 'LibraryDepartment' ||  @contact.reference_type == 'BookshopDepartment' || @contact.reference_type == 'People') %>
                <tr>
                  <td> <%= label_tag :email, t('activerecord.attributes.contact.commercial_adress') %> </td>
                  <td> <%= text_field_tag 'contact_commercial_address',@contact.reference.commercial_adress, {:disabled => true, :size => 45} %> </td>
                  <td><%=t('lbl_contact_update_address')%></td>
                </tr>
                <tr>
                  <td> <%= label_tag :email, t('activerecord.attributes.contact.postal_adress') %> </td>
                  <td> <%= text_field_tag 'contact_postal_address',@contact.reference.postal_adress, {:disabled => true, :size => 45} %> </td>
                  <td><%=t('lbl_contact_update_address')%></td>
                </tr
              <% end %>

              <% if current_user.role?(:role_admin) %>
                <tr>
                  <td>
                    <%= label_tag :treatment, t('activerecord.attributes.contact.treatment') %>
                  </td>
                  <td>
                    <%= collection_select(:contact, :treatment_id, @treatments, :id, :description, :prompt =>true) %>
                  </td>
                </tr>
                <tr>
                  <td>
                    <%= label_tag :regard, t('activerecord.attributes.contact.regard') %><br />
                  </td>
                  <td>
                    <%= collection_select(:contact, :regard_id, @regards, :id, :description, :prompt =>true) %>
                  </td>
                </tr>
                <tr>
                  <td>
                    <%= label_tag 'reference', t('activerecord.attributes.contact.reference') %>
                  </td>
                  <td>
                    <%= text_field_tag 'contact_reference_name',params[:reference_name], {:disabled => true, :size => 45} %>
                  </td>
                  <td>
                    <div id='basic-modal-customer_selector'>
                      <a href='#' class='basic'><%=t('btn_selected')%></a> |
                      <a href = 'javascript:void(0)'  onclick = "setContactCustomer('', 'contact_reference_id', '', 'contact_reference_type', '', 'contact_reference_name');"><%=t('btn_clean')%></a>
                    </div>
                  </td>                
                  <td>
                    <%= hidden_field(:contact, :reference_id)%>
                    <%= hidden_field(:contact, :reference_type) %>
                  </td>
                </tr>

                <% if !@contact.user.nil? %>
                  <% user_name = @contact.user.email %>
                <% end %>

                <tr>
                  <td>
                    <%= label_tag t('activerecord.attributes.contact.user') %>
                  </td>
                  <td>
                    <%= text_field_tag 'contact_user',user_name, {:disabled => true, :size => 30} %>
                  </td>
                  <td>
                    <div id='basic-modal-user_selector'>
                      <a href='#' class='basic'><%=t('btn_selected')%></a> |
                      <a href = 'javascript:void(0)' onclick = "setUser('','contact_user_id','','contact_user');"><%=t('btn_clean')%></a>
                    </div>
                  </td>
                  <td>
                    <%= hidden_field(:contact, :user_id)%>
                  </td>
                </tr>
                <tr>
                  <td></td>
                  <td>
                    <%="#{check_box_tag 'create_user', 'yes', false} <b>#{t('lbl_contact_create_user')}</b>"%>
                  </td>
                </tr>
              <% end %>

              <tr>
                <td>
                  <%= label_tag :language, t('activerecord.attributes.contact.language') %><br />
                </td>
                <td>
                  <%= select(:contact, :language, options_for_select(Contact::LANGUAGES.map {|u| [get_language_name(u),u]}, @contact.language), :prompt => true) %>
                </td>
              </tr>
              <tr>
                <td>
                  <%= label_tag :mail_format, t('activerecord.attributes.contact.mail_format') %><br />
                </td>
                <td>
                  <%= select(:contact, :mail_format, options_for_select(Contact::MAIL_FORMAT.map {|u| [get_mail_format_label(u),u]}, @contact.mail_format), :prompt => true) %>
                </td>
              </tr>


            </tbody>
          </table>
          <div class="line-buttons">
            <%= f.submit t('btn_save') %>
          </div>
          <div class="line-links">
            <%= link_to t('btn_show'), @contact %> |
            <% if can? :index, Contact %>
              <%= link_to t('btn_back'), contacts_redirect_back_path(contacts_path) %>
            <% else %>
              <%= link_to t('btn_back'), root_url %>
            <% end %>
          </div>
        <% end %>
  </div>

  <div class="portlet-footer">
  </div>
</div>

<div id="basic-modal-content-customer_selector" style="display:none;">
  <%= render :partial=>'customers/customers_selector' %>
</div>

<div id="basic-modal-content-user_selector" style="display:none;">
  <%= render :partial=>'localusers/selector_users' %>
</div>
